package com.kx.center.controller;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.kx.center.auth.Authentication;
import com.kx.center.entity.IosVersion;
import com.kx.center.entity.StoreAppAccount;
import com.kx.center.enumerate.MessageCode;
import com.kx.center.exception.EmptyTokenException;
import com.kx.center.exception.IllegalTokenException;
import com.kx.center.service.VersionService;
import com.kx.center.util.Response;

@Controller
@RequestMapping("/version")
public class VersionController extends CommonController{

	@Autowired
	private VersionService versionService;

	// 订货详情(共用)
	@RequestMapping(value = "iosNewVersion", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ResponseBody
	@Authentication
	public String shop_order_detail(HttpServletRequest request) throws EmptyTokenException, IllegalTokenException {

		StoreAppAccount storeAppAccount = this.getStoreAppAccount(request);
		if (storeAppAccount == null) {
			return Response.error(MessageCode.ERROR_NO_LOGIN, "未登录");
		}

		IosVersion iosVersion = versionService.findNewIosVersion();
		if(iosVersion == null){
			return Response.error(MessageCode.NO_DATA);
		}else{
			HashMap<String, Object> map = new HashMap<String, Object>();
			map.put("url", iosVersion.getUrl());
			map.put("ios_version_num", iosVersion.getVersionNum());

			return Response.success(map);
		}
	}

}
